<?php
	class myClass {
		// It sets the internal variables to the associative array $row values
		function set_from_array($row) {
			$objectArray=(array) $this;
			foreach ($row as $rowKey => $rowValue) {
				foreach ($objectArray as $obKey => $obValue) {
					if ($obKey==$rowKey) {
						$this->{$obKey}=$rowValue;
						break;
					}
				}
			}
		}
	}
	
	class myDbTb extends myClass {
		//It makes a sql request to the database, sets the object with the result for select statments and returns the success of the operation
		function sql_request($sql) {
			if (preg_match('/^select|^update|^delete|^insert/i', $sql, $match)) {
				global $server;
				$sqlType=strtolower($match[0]);
				$result = $server->db->link->query($sql);
				switch ($sqlType)  {
					case "select":
						$load_check = ($result->num_rows > 0);
						if ($load_check) {
							$this->set_from_array($result->fetch_array());
						}
						return $load_check;
					case "insert":
						$insert_check = ($server->db->link->affected_rows > 0);
						if( $insert_check ) {
							$this->id = $server->db->link->insert_id;
						}
						return $insert_check;
					case "update":
					case "delete":
						$save_check = ($server->db->link->affected_rows > 0);
						return $save_check;
				}
			}
		}
	}
?>